package com.wyj.service.imp;

import com.wyj.mapper.MessageMapper;
import com.wyj.pojo.Message;
import com.wyj.service.MessageService;
import com.wyj.util.SensitiveFilter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.util.HtmlUtils;

import java.util.List;

/**
 * @author 王永杰
 * @Description 描述该类的做什么用
 * @since 2022/7/20
 */
@Service
public class MessageServiceImp implements MessageService {

    @Autowired
    MessageMapper messageMapper;

    @Autowired
    SensitiveFilter sensitiveFilter;



    @Override
    public List<Message> getConversations(int userId, int start, int limit) {
        return messageMapper.getConversations(userId,start,limit);
    }

    @Override
    public int getConversationCount(int userId) {
        return messageMapper.getConversationCount(userId);
    }
    @Override
    public List<Message> getLetters(String conversationId, int start, int limit) {
        return messageMapper.getLetters(conversationId,start,limit);
    }

    @Override
    public int getLetterCount(String conversationId) {
        return messageMapper.getLetterCount(conversationId);
    }

    @Override
    public int getLetterUnreadCount(int userId, String conversationId) {
        return messageMapper.getLetterUnreadCount(userId,conversationId);
    }

    @Override
    public int addLetter(Message message) {
        message.setContent(HtmlUtils.htmlEscape(message.getContent()));
        message.setContent(sensitiveFilter.filter(message.getContent()));

        int i = messageMapper.addLetter(message);


        return i;
    }

    @Override
    public int updateStatus(List<Integer> ids) {

        return messageMapper.updateStatus(ids,1);
    }

    @Override
    public Message selectLatestNotice(int userId, String topic) {
        return messageMapper.selectLatestNotice(userId,topic);
    }

    @Override
    public int selectCountsNotices(int userId, String topic) {
        return messageMapper.selectCountsNotices(userId,topic);
    }

    @Override
    public int selectCountsNoReadNotices(int userId, String topic) {
        return messageMapper.selectCountsNoReadNotices(userId,topic);
    }

    @Override
    public List<Message> selectNoticesByConversationId(int userId, String topic, int offset, int limit) {
        return messageMapper.selectNoticesByConversationId(userId,topic,offset,limit);
    }

    @Override
    public int AllUnReadMessages(int userId) {
        return messageMapper.AllUnReadMessages(userId);
    }
}
